<template>
  <div>
    <h1>操作日志</h1>
    <el-form :inline="true" :model="queryLogs" class="demo-form-inline">
      <el-form-item label="系统模块">
        <el-input v-model="queryLogs.systems" placeholder="系统模块"></el-input>
      </el-form-item>
      <el-form-item label="类型">
        <el-input v-model="queryLogs.types" placeholder="操作类型"></el-input>
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="queryLogs.status" placeholder="操作状态">
          <el-option label="成功" value="0"></el-option>
          <el-option label="失败" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="操作时间">
        <el-col :span="11">
          <el-date-picker type="date" placeholder="开始日期" v-model="queryLogs.t1" style="width: 100%;"></el-date-picker>
        </el-col>
        <el-col class="line" :span="2">-</el-col>
        <el-col :span="11">
          <el-date-picker type="date" placeholder="结束日期" v-model="queryLogs.t2" style="width: 100%;"></el-date-picker>
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="list">查询</el-button><br>
      </el-form-item>
    </el-form>
    <el-button type="primary" @click="dellAll">删除</el-button>
    <el-button type="danger" @click="daochu">导出</el-button>
    <el-button type="warning" @click="reload">重置</el-button>

    <el-table
        :data="tableData"
        stripe
        style="width: 100%"
        @selection-change="handleSelectionChange"
    >
      <el-table-column
          type="selection"
          width="55">
      </el-table-column>
      <el-table-column
          prop="logNo"
          label="日志编号"
          width="180">
      </el-table-column>
      <el-table-column
          prop="systems"
          label="系统模块"
          width="180">
      </el-table-column>
      <el-table-column
          prop="types"
          label="操作类型">
      </el-table-column>
      <el-table-column
          prop="methods"
          label="请求方式">
      </el-table-column>
      <el-table-column
          prop="creater"
          label="操作人员">
      </el-table-column>
      <el-table-column
          prop="ip"
          label="主机">
      </el-table-column>
      <el-table-column
          prop="address"
          label="地点">
      </el-table-column>
      <el-table-column
          label="状态">
        <template v-slot="s">
          <el-tag v-if="s.row.status==0">成功</el-tag>
          <el-tag v-if="s.row.status==1">失败</el-tag>
        </template>
      </el-table-column>
      <el-table-column
          prop="times"
          label="操作日期">
      </el-table-column>
      <el-table-column label="操作">
        <template v-slot="s">
          <el-button @click="delByFlag(s.row.id)" type="primary">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        @current-change="handleCurrentChange"
        :page-size="size"
        layout="total, prev, pager, next"
        :total="total">
    </el-pagination>
  </div>
</template>

<script>
import {API} from "@/api/config";

export default {
  name: "ControlsLogsView",
  data(){
    return{
      tableData:[],
      current:1,
      size:2,
      total:0,
      queryLogs:{},
      ids:[]
    }
  },methods:{
    handleSelectionChange(rows){
      this.ids=rows.map(item =>item.id).join(",")
      console.log(this.ids)
    },
    handleCurrentChange(current){
      this.current=current;
      this.list();
    },
    list(){
      this.axios.post("/logs/ControlsLogsList?current="+this.current+"&size="+this.size,this.queryLogs).then(r =>{
        this.tableData=r.data.data.list;
        this.total=r.data.data.total;
      })
    },
    delByFlag(id){
      console.log(id)
      this.axios.post("/logs/delByflag?id="+id).then(() =>{
        this.$message.success("删除成功");
        this.list();
      })
    },
    dellAll(){
      this.axios.post("/logs/dellAll?ids="+this.ids).then(() =>{
        this.$message.success("删除成功");
        this.list();
      })
    },
    daochu(){
    window.location.href=API+"/logs/daochu"
    },
    reload(){
      location.reload();
    }
  },created() {
    this.list();
  }
}
</script>

<style scoped>

</style>